package com.fjh.springboot_01.mapper;

import com.fjh.springboot_01.pojo.Banner;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BannerMapper {
    
    @Select("SELECT * FROM banner WHERE status = 1 ORDER BY sort ASC, create_time DESC")
    List<Banner> selectActiveBanners();
    
    @Select("SELECT * FROM banner ORDER BY sort ASC, create_time DESC")
    List<Banner> selectAllBanners();
    
    @Insert("INSERT INTO banner (title, image_url, link, sort, status, create_time, update_time) " +
            "VALUES (#{title}, #{imageUrl}, #{link}, #{sort}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Banner banner);
    
    @Update("UPDATE banner SET title = #{title}, image_url = #{imageUrl}, link = #{link}, " +
            "sort = #{sort}, status = #{status}, update_time = #{updateTime} WHERE id = #{id}")
    int update(Banner banner);
    
    @Delete("DELETE FROM banner WHERE id = #{id}")
    int deleteById(Integer id);
    
    @Select("SELECT * FROM banner WHERE id = #{id}")
    Banner selectById(Integer id);
} 